package org.jeecg.modules.engineering.util;

import org.jeecg.common.constant.CommonConstant;
import org.jeecg.modules.engineering.entity.EquipCollectTrigger;

import java.util.List;

public class EngineeringUtil {

    public static String getEventByTriggers(List<EquipCollectTrigger> triggers,String value){
        String eventIds = "";
        Integer type = triggers.get(0).getCompareType();
        float floatValue = Float.parseFloat(value);
        for (EquipCollectTrigger trigger : triggers){
            if(CommonConstant.COMPARE_TYPE_EQUAL.equals(type)){
                if(floatValue == trigger.getFirstValue()){
                    eventIds = trigger.getEventSortId()+","+trigger.getId();
                    break;
                }
            }else if(CommonConstant.COMPARE_TYPE_GREATER.equals(type)){
                if(floatValue > trigger.getFirstValue()){
                    eventIds = trigger.getEventSortId()+","+trigger.getId();
                }
            }else if(CommonConstant.COMPARE_TYPE_LESS.equals(type)){
                if(floatValue < trigger.getFirstValue()){
                    eventIds = trigger.getEventSortId()+","+trigger.getId();
                    break;
                }
            }else if(CommonConstant.COMPARE_TYPE_BETWEEN.equals(type)){
                if(floatValue > trigger.getFirstValue() && floatValue < trigger.getLastValue()){
                    eventIds = trigger.getEventSortId()+","+trigger.getId();
                    break;
                }
            }
        }
        return eventIds;
    }
}
